const Sequelize = require('sequelize')
let db = require('../config/db')
let User = require('./user')

let Company = db.define('company',{
    id:{
        type: Sequelize.INTEGER,
        field: 'id',
        primaryKey:true,
        autoIncrement: true,
        comment: "主键，自增"
    },
    uid:{
        type: Sequelize.INTEGER
    },
    type:{
        type: Sequelize.INTEGER
    },
    name:{
        type:Sequelize.STRING,
        comment:'名称'
    },
    short_name:{
        type:Sequelize.STRING,
        comment:'简称'
    },
    logo:{
        type:Sequelize.STRING,
        comment:'公司logo'
    },
    address:{
        type:Sequelize.STRING,
        comment:'地址'
    },
    phone:{
        type:Sequelize.BIGINT(),
        comment:'电话'
    },
    contact_person:{
        type:Sequelize.STRING,
        comment:'联系人'
    },
    legal_person:{
        type:Sequelize.STRING,
        comment:'法定代表人'
    },
    intro:{
        type:Sequelize.TEXT,
        comment:'介绍'
    },
    license_img:{
        type:Sequelize.STRING,
        comment:'营业执照'
    },
    isDel:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'状态，是否删除'
    },
    deletedAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('deletedAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
    createdAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
    updatedAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    }
},{
    freezeTableName:true,
    paranoid:true,
    timestamps:true
})
Company.belongsTo(User, {foreignKey: 'uid', targetKey: 'uid'});
let company = Company.sync();
module.exports = Company
